package com.bytedance.common.utility.c;

import android.annotation.TargetApi;
import android.content.SharedPreferences;
import android.os.Build;

public final class SharedPreferenceCompat {
    final static class CommitExecutorImpl implements CommitExecutor {
        CommitExecutorImpl() {

        }

        public final void commit(SharedPreferences.Editor editor) {
            editor.commit();
        }
    }

    interface CommitExecutor {
        void commit(SharedPreferences.Editor editor);
    }

    final static class CommitExecutorApi9 implements CommitExecutor {
        CommitExecutorApi9() {

        }

        @TargetApi(value=Build.VERSION_CODES.GINGERBREAD)
        public final void commit(SharedPreferences.Editor editor) {
            editor.apply();
        }
    }

    private static CommitExecutor executor = Build.VERSION.SDK_INT >= 9 ? new CommitExecutorApi9() : new CommitExecutorImpl();

    public static void commit(SharedPreferences.Editor editor) {
        if(editor != null) {
            SharedPreferenceCompat.executor.commit(editor);
        }
    }
}

